package com.train.fibonacci.generate;

import com.train.fibonacci.report.FibonacciReporter;

public class LoopFibonacciGenerator implements FibonacciGenerator {

	@Override
	public void generate(int length, FibonacciReporter reporter) {
		if (length < 0) {
			throw new IllegalArgumentException();
		}
		
		if (length > 0) {
			reporter.report(A);
		}
		
		if (length > 1) {
			reporter.report(B);
		}
		
		long a = A;
		long b = B;
		long current;
		for (int i = 2; i < length; i++) {
			current = a + b;
			reporter.report(current);
			
			a = b;
			b = current;
		}
	}
	
}
